home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / uupc.lzh / uupc / ulib.c < prev    next >
C/C++ Source or Header  |  1990-01-16  |  6KB  |  295 lines

  1. /*
  2.  *    ulib.c
  3.  *
  4.  *    Amiga UUPC library
  5.  *
  6.  *    $Id: ulib.c,v 1.2 90/01/16 10:27:53 crash Exp Locker: crash $
  7.  */
  8.  
  9. #ifndef lint
  10. static char RCSid[] = "$Id: ulib.c,v 1.2 90/01/16 10:27:53 crash Exp Locker: crash $";
  11. #endif /* lint */
  12.  
  13. #include <stdio.h>
  14. #include "host.h"
  15.  
  16. #if 0
  17. #  if MCH_AMIGA            /* If Manx C */
  18. #   include <sgtty.h>
  19. #  endif
  20. #endif
  21.  
  22. /*
  23.  *    login (for slave in PC mode)
  24.  *
  25.  *    Real dumb login handshake
  26.  */
  27.  
  28. login()
  29. {
  30.     char    logmsg[132];
  31. #ifdef PC
  32. lretry:
  33.     msgtime = 9999;
  34.     rmsg(logmsg, 0); /* wait for a <CR> or <NL> */
  35.     msgtime = 2 * MSGTIME;
  36.     wmsg("Login: ", 0);
  37.     rmsg(logmsg, 0);
  38.     printmsg( 0, "login = %s", logmsg );
  39.     wmsg("Password:", 0);
  40.     rmsg(logmsg, 0);
  41.     printmsg( 14, "Password = %s", logmsg );
  42.     if (strcmp(logmsg, "uucp") != 0)
  43.         goto lretry;
  44. #endif
  45.     return('I');
  46. }
  47.  
  48. char inbuf[BUFSIZ];
  49. char outbuf[BUFSIZ];
  50.  
  51. swrite(data, num)
  52. int    num;
  53. char    *data;
  54. {
  55.     int test;
  56.     unsigned char * cp;
  57.  
  58.     test = SIOWrite( data, num );
  59.     return( test );
  60. }
  61.  
  62.  
  63. /*
  64.  *    non-blocking read essential to "g" protocol
  65.  *
  66.  *    see "dcpgpkt.c" for description
  67.  *
  68.  *    This all changes in multitask systems.  Requests for
  69.  *    I/O should get queued and an event flag given.  Then the
  70.  *    requesting process (e.g. gmachine()) waits for the event
  71.  *    flag to fire, processing either a read or a write.
  72.  *
  73.  *    Could be implemented on VAX/VMS or DG but not MS-DOS.
  74.  */
  75.  
  76. sread(buf, num, timeout)
  77. char    *buf;
  78. int    num, timeout;
  79. {
  80. #if 0
  81.     return( SIORead( buf, num, num, timeout*10 ) );
  82. #endif
  83.     int count;
  84.     int test;
  85.     unsigned char * cp;
  86.  
  87.     if (debuglevel > 13)
  88.         fputc( '[', stderr );
  89.     printmsg( 15, "sread: num: %d  timeout: %d", num, timeout );
  90.  
  91.     count = SIORead( buf, num, num, timeout*10 );
  92.     printmsg( 15, "sread: read: %d ", count );
  93.  
  94.     if (debuglevel > 13 && count > 0) {
  95.         test = count;
  96.         cp = (unsigned char *) buf;
  97.         while (test--)
  98.             fprintf( stderr, isprint(*cp)? "[%c]":"[%02x]", *cp++ );
  99.     }
  100.     if (debuglevel > 13)
  101.         fputc( ']', stderr );
  102.     return( count );
  103. }
  104.  
  105. openline(name, baud)
  106. char    *name, *baud;
  107. {
  108.     printmsg( 3, "openline: name: \"%s\"  baud: \"%s\"", name, baud );
  109.     if ( SIOInit( name, baud ) )
  110.         return -1;
  111.     SIOInBuffer( inbuf, BUFSIZ );
  112.     SIOOutBuffer( outbuf, BUFSIZ );
  113.     return( 0 );
  114. }
  115.  
  116. closeline()
  117. {
  118.     SIOClose( 1 );
  119. }
  120.  
  121. void nodot(string)
  122. {
  123.     return;
  124. }
  125.  
  126. notimp( argc, argv )
  127. char *argv[];
  128. {
  129.     fprintf( stderr, "shell: %s not implemented\n", *argv );
  130. }
  131.  
  132. /*
  133.  *    RNews:    my private rnews!
  134.  *
  135.  *        C-News would call a shell script which gives its' stdin to a
  136.  *        program called "newsspool".  The newsspool program scans the input
  137.  *        and peels off the "#! c[7]unbatch" header and then puts the file
  138.  *        into $NEWSART/in.coming/nspool.XXXXXX
  139.  *
  140.  *        So what we do here is call that "newsspool" program as a function.
  141.  *        See the file "rnews.c"
  142.  */
  143. #ifdef CNEWS
  144. static void RNews( inname )
  145. char *inname;
  146. {
  147.     int        dummy;
  148.     char    *argv[3];
  149.  
  150.     argv[0] = "built_in_rnews";
  151.     argv[1] = (char *) NULL;
  152.     argv[2] = (char *) NULL;
  153.  
  154.     freopen( inname, "r", stdin );
  155.     dummy = debuglevel;                /* Turn off debugging... */
  156.     debuglevel = 0;
  157.     rnews( 1, argv );
  158.     debuglevel = dummy;                /* Turn it back on */
  159.     freopen( "*", "r", stdin );
  160. }
  161. #else /* !CNEWS */
  162. static void RNews( inname )
  163. char *inname;
  164. {
  165.     extern    char *newsdir;
  166.     register struct tm    *thetm;
  167.     long    tloc;
  168.     char    filename[132];
  169.     char    format[128];
  170.     FILE     *f, *fin;
  171.     FILE    *FOPEN();
  172.     char    buf[BUFSIZ];
  173.  
  174.     static int count = 0;
  175.     int    len;
  176.  
  177.     /* inname is of form "D.jlamiBCnnnn".  Pick off the nnnn. */
  178.     len = strlen( inname ) - 1;
  179.     while ( len >= 0 ) {
  180.         if ( '0' <= inname[len] && inname[len] <= '9' )
  181.             --len;
  182.         else
  183.             break;
  184.     }
  185.     sprintf( filename, "%s/%s", newsdir, &inname[len+1] );
  186.     if ( (f = FOPEN( filename, "r" )) != NULL ) {
  187.         /* Already exists, so make a timestamped one. */
  188.         fclose( f );
  189.         tloc = time( (long *)NULL );
  190.         thetm = localtime( &tloc );
  191.  
  192.         sprintf( filename, "%s/%02d%02d%02d%02d%02d%02d.%03d",
  193.             newsdir,
  194.             thetm->tm_year % 100, thetm->tm_mon,
  195.             thetm->tm_mday, thetm->tm_hour,
  196.             thetm->tm_min,  thetm->tm_sec,  count);
  197.         ++count;
  198.     }
  199.     fprintf( stderr, "rnews: %s\n", filename );
  200.  
  201.     /*
  202.      *    The file-types are binary 'cuz the news comes in compressed.
  203.      */
  204.  
  205.     if ( (f = FOPEN( filename, "w", 'b' )) == (FILE *)NULL ) {
  206.         fprintf( stderr, "rnews: can't open %s\n", filename );
  207.         return;
  208.     }
  209.     if ( (fin = FOPEN( inname, "r", 'b' )) == NULL ) {
  210.         fprintf( stderr, "rnews: Couldn't open %s\n", inname );
  211.         fclose( f );
  212.         return;
  213.     }
  214.     while ( tloc = fread(buf, 1, BUFSIZ, fin) )
  215.         fwrite(buf, 1, tloc, f);
  216.  
  217.     fclose( f );
  218.     fclose( fin );
  219. }
  220. #endif /* !CNEWS */
  221.  
  222. /*
  223.  *    shell
  224.  */
  225.  
  226. char *getcwd();
  227.  
  228. shell( command, inname, outname, errname )
  229. char *command, *inname, *outname, *errname;
  230. {
  231. #ifdef AMIGA
  232. # ifdef FJE
  233.     FILE    tmp_stdout, tmp_stderr;
  234.     extern    FILE *logfile;
  235. # endif
  236. #endif
  237.     char    *argvec[50];
  238.     int        rmail();
  239.     int        rnews();
  240.     int     argcp, args;
  241.     char    **argvp;
  242.     int        (*proto)();
  243.  
  244.     argcp = getargs( command, argvec );
  245.     argvp = argvec;
  246.  
  247.     if ( debuglevel > 5 ) {
  248.         args = argcp;
  249.         while ( args )
  250.             fprintf( stderr, "arg: %d  %s\n", args--, *argvp++ );
  251.         argvp = argvec;
  252.         args = argcp;
  253.     }
  254.     proto = notimp;
  255.     if ( strcmp( *argvp, "rmail" ) == SAME )
  256.         proto = rmail;
  257.     else if ( strcmp( *argvp, "rnews" ) == SAME ) {
  258.         /* proto = rnews; */
  259.         RNews( inname );
  260.         return;
  261.     }
  262. #ifdef AMIGA
  263. # ifdef FJE
  264.     if (!outname || !*outname) {
  265.         fprintf( stderr, "assigning stdout to LOGFILE\n" );
  266.         tmp_stdout = *stdout;
  267.         *stdout = *logfile;
  268.     }
  269.     if (!errname || !*errname) {
  270.         fprintf( stderr, "assigning stderr to LOGFILE\n" );
  271.         tmp_stderr = *stderr;
  272.         *stderr = *logfile;
  273.     }
  274. # endif /* FJE */
  275. #endif /* AMIGA */
  276.  
  277.     if ( *inname != '\0' ) {
  278.         printmsg( 2, "reopening stdin as %s\n", inname );
  279.         printmsg( 2, "curdir: %s\n", getcwd(NULL, 0));
  280.         if ( freopen( inname, "r", stdin ) == NULL )
  281.             printmsg( 0, "Couldn't open %s: %d\n", inname, errno );
  282.     }
  283.     (*proto)( argcp, argvp );
  284.  
  285. #ifdef AMIGA
  286.     freopen( "*", "r", stdin );
  287. # ifdef FJE
  288.     *stdout = tmp_stdout;
  289.     *stderr = tmp_stderr;
  290. # endif /* FJE */
  291. #else /* !AMIGA */
  292.     freopen( device, "r", stdin );
  293. #endif /* !AMIGA */
  294. }
  295.